package org.millioncall.yueyoga.admin.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.millioncall.openplatform.common.PaginateParams;
import org.millioncall.openplatform.common.PaginatedList;
import org.millioncall.openplatform.common.StartLimitPairImpl;
import org.millioncall.openplatform.dao.PreparedQuery;
import org.millioncall.yueyoga.admin.dao.BaseDao;
import org.millioncall.yueyoga.admin.dao.HallDAO;
import org.millioncall.yueyoga.admin.model.Hall;
import org.springframework.stereotype.Repository;
@Repository
public class HallDAOImpl extends BaseDao implements HallDAO {

	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int insert(Hall record) {
		return this.getPagableSqlSessionTemplate().insert("saveHall", record);
	}

	@Override
	public int insertSelective(Hall record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Hall selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int updateHallById(Hall record) {
		return this.getPagableSqlSessionTemplate().update("updateHallById",record);
	}

	@Override
	public int updateByPrimaryKey(Hall record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Hall> findHalls() {
		return this.getPagableSqlSessionTemplate().selectList("findHalls");
	}

	@Override
	public Hall findByName(String name) {
		return this.getPagableSqlSessionTemplate().selectOne("findHallByName",name);
	}

	@Override
	public Hall findByCode(String code) {
		return this.getPagableSqlSessionTemplate().selectOne("findHallByCode",code);
	}

	@Override
	public PaginatedList<Hall> getStatusInPage(int start, int limit) {
		PreparedQuery<Hall> pq = this.getPagableSqlSessionTemplate().findAll("findHalls");
		PaginatedList<Hall> pl = pq.list(new PaginateParams(new StartLimitPairImpl(start, limit)));
		return pl;
	}

	@Override
	public void deleteByIds(Integer[] deids) {
		Map<String, Object> map = new HashMap<String, Object>();
		for (int i = 0; i < deids.length; i++) {
			map.put("id", deids[i]);
			this.getPagableSqlSessionTemplate().insert("deleteHall", map);
		}
	}
	
	@Override
	public List<Hall> findHallsByGroupId(int gpId) {
		List<Hall> halls = this.getPagableSqlSessionTemplate().selectList(
				"findHallsByGroupId", gpId);
		return halls;
	}

}
